package com.honglv.controller.common;

import com.honglv.exception.BaseException;
import com.honglv.pojo.dto.PageByCityDTO;
import com.honglv.pojo.result.Result;
import com.honglv.pojo.vo.GetCommoditiesByCityVO;
import com.honglv.pojo.vo.PageVO;

import com.honglv.service.CommodityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@Api("文创相关接口")

public class CommodityController {
    @Autowired
    private CommodityService commodityService;

    /**
     * 根据城市分页获取文创
     * @param
     * @return
     */
    @GetMapping("/getCommoditiesByCity")
    @ApiOperation("根据城市分页获取文创")
    public Result<PageVO<GetCommoditiesByCityVO>> getCommoditiesByCity(PageByCityDTO pageByCityDTO){
        if (pageByCityDTO == null || pageByCityDTO.getPageSize() == null || pageByCityDTO.getPage() == null){
            throw new BaseException("参数为空");
        }
        PageVO<GetCommoditiesByCityVO> pageVO = commodityService.getCommoditiesByCity(pageByCityDTO);
        if (pageVO == null){
            return Result.success("暂无文创数据");
        }
        return Result.success(pageVO);
    }
}
